package ru.tulupov.toyfactory;

import java.util.Scanner;

import ru.tulupov.toyfactory.model.Playable;
import ru.tulupov.toyfactory.pattern.Consumer;
import ru.tulupov.toyfactory.pattern.Producer;
import ru.tulupov.toyfactory.pattern.Storage;
import ru.tulupov.toyfactory.pattern.impl.PlayableConsumer;
import ru.tulupov.toyfactory.pattern.impl.TVProducer;
import ru.tulupov.toyfactory.pattern.impl.ToyProducer;

public class Main {
	private static final int STORAGE_CAPACITY = 10;

	public static void main(String[] args) throws Exception {
		Storage<Playable> storage = new Storage<Playable>(STORAGE_CAPACITY);
		Producer<Playable> toyProducer = new ToyProducer(storage);
		Producer<Playable> tvProducer = new TVProducer(storage);
		Consumer<Playable> consumer = new PlayableConsumer(storage);
		Consumer<Playable> consumer2 = new PlayableConsumer(storage);

		toyProducer.start();
		tvProducer.start();
		consumer.start();
		consumer2.start();

		System.out.println("The toy factory");
		System.out.println("Type 'exit' to close the application.");
		System.out.println();
		System.out.print("# ");
		Scanner scanner = new Scanner(System.in);
		while (scanner.hasNextLine()) {

			String line = scanner.nextLine();
			if (line.equals("exit")) {
				consumer.interrupt();
				break;
			} else {
				System.err.println("Invalid command!");
			}
			System.out.print("# ");
		}
	}

}
